import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:furaha_mkopo/page/authentication/dialog/fm_image_picker_manager.dart';
import 'package:image_picker/image_picker.dart';

class FMCupertinoImagePickerSheet {
  static Future<File?> showImageSourceSelector(BuildContext context,{Function(String source)? imageSource}) async {
    final result = await showCupertinoModalPopup<ImageSource?>(
      context: context,
      builder: (BuildContext context) => CupertinoActionSheet(
        title: const Text('Select image source',
            style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500)),
        cancelButton: CupertinoActionSheetAction(
          onPressed: () => Navigator.pop(context),
          child: const Text('Cancel',
              style: TextStyle(color: Colors.blue, fontSize: 16)),
        ),
        actions: <Widget>[
          CupertinoActionSheetAction(
            onPressed: () => Navigator.pop(context, ImageSource.camera),
            child: const Text('Take Photo',
                style: TextStyle(color: Colors.blue, fontSize: 16)),
          ),
          CupertinoActionSheetAction(
            onPressed: () => Navigator.pop(context, ImageSource.gallery),
            child: const Text('Select from the album',
                style: TextStyle(color: Colors.blue, fontSize: 16)),
          ),
        ],
      ),
    );

    if (result == null) return null;
    // 使用之前封装的图片选择管理器
    imageSource?.call(result == ImageSource.camera ? '1' : '2');
    final image = await FMImagePickerManager().pickImage(result);
    return image;
  }


  static Future<File?> showImageSourceTakePhoto(BuildContext context,{Function(String source)? imageSource}) async {
    // 使用之前封装的图片选择管理器
    imageSource?.call('1');
    final image = await FMImagePickerManager().pickImage(ImageSource.camera,preferredCameraDevice: CameraDevice.front);
    return image;
  }

}
